package textFileWorkerWrapper;

import java.util.ArrayList;
import org.apache.log4j.Logger;

import com.danco.training.TextFileWorker;

public class TextFileWorkerWrapper {
	private static final Logger log=Logger.getLogger(TextFileWorkerWrapper.class);
	private TextFileWorker tfw;
	
	public TextFileWorkerWrapper(String path) {
		try{
		tfw = new TextFileWorker(path);
		}catch(IllegalArgumentException e){
			log.error("File not found.Please check the entered path");
		}
				
	}

	public ArrayList<String> readFromFile() {

		ArrayList<String> arr = new ArrayList<String>();
		try{

		for (String s : tfw.readFromFile()) {
			arr.add(s);
		}
		}catch(NullPointerException e){
			log.error("Check the entered path or file is full");
		}
		

		return arr;
	}
	
	public void writeToFile(ArrayList<String> arr){
		String array[]=new String[arr.size()];
		
		for(int i=0;i<arr.size();i++){
			array[i]=arr.get(i);
		}
		
		tfw.writeToFile(array);
		
	}

}
